package com.jdl.iscm.page;

import com.jdl.iscm.common.CommonCmpt;
import com.jdl.iscm.common.DimensionCmpt;
import com.jdl.iscm.common.JoinUtil;
import com.jdl.iscm.entity.excel.RssExcel;
import com.jdl.iscm.entity.proterties.ReplenishXpathProperties;
import com.jdl.iscm.page.interfaces.ManualAddInterface;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Ran
 * @Date: 2021/8/23
 **/
@Component
public class RssPage implements ManualAddInterface<RssExcel> {

    @Autowired
    private CommonCmpt commonCmpt;

    @Autowired
    private DimensionCmpt dimensionCmpt;


    /**
     * 手工添加
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAdd(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigAdd());
    }

    /**
     * 手工添加设置
     *
     * @param webDriver
     * @param xpathProperties
     * @param rssExcel
     */
    @Override
    public void manualAddSetting(WebDriver webDriver, ReplenishXpathProperties xpathProperties, RssExcel rssExcel) {
        //先取消勾选
        commonCmpt.click(webDriver, xpathProperties.getConfigDimSku());
        //1、设置场景
        List<String> scenesXpath = rssExcel.getSceneList().stream().map(scene -> JoinUtil.textJoin(xpathProperties, scene)).collect(Collectors.toList());
        commonCmpt.drpDwnClick(webDriver, xpathProperties.getConfigSceneInput(), scenesXpath);
        //2、设置bp
        commonCmpt.input(webDriver, xpathProperties.getConfigStrategyBpInput(), rssExcel.getBp());
        //3、设置nrtk
        commonCmpt.input(webDriver, xpathProperties.getConfigStrategyNrtkInput(), rssExcel.getNrtk());
        //4、设置k
        commonCmpt.input(webDriver, xpathProperties.getConfigStrategyKInput(), rssExcel.getK());
        //5、根据配置的维度设置
        dimensionCmpt.setDimValueByDimKey(webDriver, xpathProperties, rssExcel.getDimensionMap());

    }

    /**
     * 手工添加提交
     *
     * @param webDriver
     * @param xpathProperties
     */
    @Override
    public void manualAddSubmit(WebDriver webDriver, ReplenishXpathProperties xpathProperties) {
        commonCmpt.click(webDriver, xpathProperties.getConfigSubmit());
    }
}
